package col.calculator.ua;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.BorderLayout;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction;
import javax.swing.text.JTextComponent;

import org.eclipse.wb.swing.FocusTraversalOnArray;
//import org.kolyas.domain.GoodBean;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.StringCharacterIterator;

public class MainWindowCalc {

	private final class OperationLisener implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub
			calculator.addOperation(e.getActionCommand());
			scoreboard.setText(calculator.getScoreboard());
		}
	}

	private final class DigitLisener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			 calculator.addDigital(e.getActionCommand());
			 scoreboard.setText(calculator.getScoreboard());
		 }
	}

	private JFrame frame;
	private JTextField scoreboard;
	private MyCalculator calculator;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					MainWindowCalc window = new MainWindowCalc();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	

	/**
	 * Create the application.
	 */
	public MainWindowCalc() {
		initialize();
	}
	
	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		calculator = new MyCalculator();
		frame = new JFrame();
		frame.setTitle("\u041A\u0430\u043B\u044C\u043A\u0443\u043B\u044F\u0442\u043E\u0440");
		frame.setBounds(100, 100, 227, 198);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		scoreboard = new JTextField();
		scoreboard.setBounds(10, 11, 200, 31);
		frame.getContentPane().add(scoreboard);
		scoreboard.setColumns(10);
		scoreboard.setHorizontalAlignment (JTextField.RIGHT );
	
		
		
		JButton seven = new JButton("7");
		seven.setBounds(10, 53, 45, 23);
		frame.getContentPane().add(seven);
		seven.addActionListener(new DigitLisener());
		
		
				
		JButton four = new JButton("4");
		four.setBounds(10, 79, 45, 23);
		frame.getContentPane().add(four);
//		four.addActionListener(new ActionListener() {
//			public void actionPerformed(ActionEvent e) {
//				scoreboard.setText(e.getActionCommand());
//			}
//		});
		four.addActionListener(new DigitLisener());
		
		JButton one = new JButton("1");
		one.setBounds(10, 105, 45, 23);
		frame.getContentPane().add(one);
		one.addActionListener(new DigitLisener());
		
		JButton clear = new JButton("\u0441");
		clear.setBounds(10, 131, 45, 23);
		frame.getContentPane().add(clear);
		
		JButton eight = new JButton("8");
		eight.setBounds(60, 53, 45, 23);
		frame.getContentPane().add(eight);
		eight.addActionListener(new DigitLisener());
		
		JButton five = new JButton("5");
		five.setBounds(60, 79, 45, 23);
		frame.getContentPane().add(five);
		five.addActionListener(new DigitLisener());
		
		JButton two = new JButton("2");
		two.setBounds(60, 105, 45, 23);
		frame.getContentPane().add(two);
		two.addActionListener(new DigitLisener());
		
		JButton zero = new JButton("0");
		zero.setBounds(60, 131, 45, 23);
		frame.getContentPane().add(zero);
		zero.addActionListener(new DigitLisener());
		
		JButton nine = new JButton("9");
		nine.setBounds(109, 53, 45, 23);
		frame.getContentPane().add(nine);
		nine.addActionListener(new DigitLisener());
		
		JButton six = new JButton("6");
		six.setBounds(109, 79, 45, 23);
		frame.getContentPane().add(six);
		six.addActionListener(new DigitLisener());
		
		JButton three = new JButton("3");
		three.setBounds(109, 105, 45, 23);
		frame.getContentPane().add(three);
		three.addActionListener(new DigitLisener());
		
		JButton point = new JButton(".");
		point.setBounds(109, 131, 45, 23);
		frame.getContentPane().add(point);
		point.addActionListener(new DigitLisener());
		
		
		JButton divide = new JButton("/");
		divide.setBounds(165, 53, 45, 23);
		frame.getContentPane().add(divide);
		divide.addActionListener(new OperationLisener());
		
		JButton multiplied = new JButton("*");
		multiplied.setBounds(165, 79, 45, 23);
		frame.getContentPane().add(multiplied);
		multiplied.addActionListener(new OperationLisener());
		
		JButton minus = new JButton("-");
		minus.setBounds(165, 105, 45, 23);
		frame.getContentPane().add(minus);
		minus.addActionListener(new OperationLisener());
		
		JButton plus = new JButton("+");
		plus.setBounds(165, 131, 45, 23);
		frame.getContentPane().add(plus);
		plus.addActionListener(new OperationLisener());
		frame.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{frame.getContentPane(), scoreboard, seven, four, one, clear, eight, five, two, zero, nine, six, three, point, divide, multiplied, minus, plus}));
	}
}
